<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('风险管理') }}</span>
    </div>
    <div class="area-header" />
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('项目名称')" prop="dealName">
        <el-input
          v-model="queryParams.dealName"
          :placeholder="$t('项目名称')"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item :label="$t('风险名称')" prop="riskName">
        <el-input
          v-model="queryParams.riskName"
          :placeholder="$t('风险名称')"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item :label="$t('风险等级')" prop="riskLevel">
        <dictSelect
          v-model="queryParams.riskLevel"
          :clearable="true"
          dictionary="level"
          size="small"
        />
      </el-form-item>
      <el-form-item :label="$t('损失程度')" prop="loss">
        <dictSelect
          v-model="queryParams.loss"
          :clearable="true"
          dictionary="level"
          size="small"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="list" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目名称')" align="center" prop="dealName" show-overflow-tooltip />
      <el-table-column :label="$t('风险名称')" align="center" prop="riskName" show-overflow-tooltip />
      <el-table-column :label="$t('风险时间')" align="center" prop="happenTime" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.riskTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('风险等级')" align="center" prop="riskLevel" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ getDictVaule('levelOptions', scope.row.riskLevel) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('风险类型')" align="center" prop="riskType" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ getDictVaule('riskTypeOptions', scope.row.riskType) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('损失程度')" align="center" prop="loss" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ getDictVaule('levelOptions', scope.row.loss) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('备注')" align="center" prop="remark" show-overflow-tooltip />

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { dealRiskStatisticsInfo } from '@/api/deal/risk/dealRisk'

export default {
  components: {},
  props: {
    listSon: {
      type: Object,
      default: undefined
    }
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      list: [],
      // 查询参数
      queryParams: {
        dealName: undefined,
        riskLevel: undefined,
        loss: undefined,
        pageNum: 1,
        pageSize: 10,
        data: 1
      },
      levelOptions: [],
      riskTypeOptions: []
    }
  },
  watch: {
    listSon: {
      handler(newVal) {
        this.listSon = newVal
        this.getList()
      },
      deep: true
    }

  },
  created() {
    // 初始化字典
    this.getDict()
    this.getList()
  },
  methods: {
    /** 查询项目跟踪列表 */
    getList() {
      this.loading = true
      this.queryParams.jd = this.listSon.jd
      this.queryParams.date = this.listSon.date
      this.queryParams.riskType = this.listSon.riskType
      dealRiskStatisticsInfo(this.queryParams).then(response => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    getDict() {
      this.getDicts('level').then(response => {
        this.levelOptions = response.data
      })
      this.getDicts('risk_type').then(response => {
        this.riskTypeOptions = response.data
      })
    },
    getDictVaule(listName, key) {
      const list = this[listName]
      for (let i = 0; i < list.length; i++) {
        const dict = list[i]
        if (dict.dictValue === key) {
          return dict.dictLabel
        }
      }
    },
    clearParam() {
      this.queryParams = {
        dealName: undefined,
        riskLevel: undefined,
        loss: undefined,
        pageNum: 1,
        pageSize: 10,
        data: 1
      }
    }

  }
}
</script>
